/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.cip.esymons.tesoreria.converters;

import org.cip.esymons.general.util.ControladorAbstracto;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import org.cip.esymons.tesoreria.be.FormaPago;
import org.cip.esymons.tesoreria.beans.FormaPagoController;

/**
 *
 * @author Gilmar
 */
public class FormaPagoConverter implements Converter{
    @Override
    public Object getAsObject(FacesContext context, UIComponent component, String value) {
      if (value == null ) {
            return null;
        }

        try {
            Integer id = new Integer(value);
            FormaPagoController controller = (FormaPagoController) ControladorAbstracto.getBean("formaPagoController");
            return controller.buscarPorCodigo(id);
        } catch (Exception ex) {
            ex.printStackTrace();
            return null;
        }
    }

    @Override
    public String getAsString(FacesContext context, UIComponent component, Object object) {
       if (object == null) {
            return null;
        }
        if (object instanceof FormaPago) {
            FormaPago ba = (FormaPago) object;
            return "" + ba.getFpaCodigo();
        } else {
            return null;
        }
    }
}
